home *** CD-ROM | disk | FTP | other *** search
- Path: dragon.cs.hku.hk!kwho
- From: kwho@csd.hku.hk (Lord Hermes)
- Newsgroups: comp.lang.c++
- Subject: Problem with CBitmapButton::AutoLoad()
- Date: 3 Feb 1996 23:55:30 GMT
- Organization: Department of Computer Science, The University of Hong Kong
- Message-ID: <4f0sli$9ge@ns.cs.hku.hk>
- NNTP-Posting-Host: dragon.cs.hku.hk
- X-Newsreader: TIN [version 1.2 PL2]
-
- I'm new to VC++ programming and am currently using VC++ 2.0 under
- Windows 95...
-
- I've encountered a strange problem with the method AutoLoad() of
- the CBitmapButton class, the method fails to locate the bitmap
- file in my dialog-based application. I've traced the code with the
- debugger and find out the problem is that the program fails to get
- the bitmap when it gets to the point to retrieve resource CLASSU (
- see below, pls), which leads to an exeception... The bitmap files
- are stored in ".\res\" and the Visual Workbench can corretly locate
- it for me to edit the bitmap. (Actually I created them using the
- visual workbench) I'm following the method discribed in the book
- "Visual C++ Power Toolkit" by Richard C. Leinecker and Jamie Nye.
- It works for their tutorial exercise but...
-
- If you happen to know what have I done wrong. May I ask u for some
- advice, pls? Thanx in advance.
-
- >=== SR.RC (Resource file -- truncated a bit) ===================<
-
- //Microsoft Visual C++ generated resource script.
- //
- #include "resource.h"
-
- #define APSTUDIO_READONLY_SYMBOLS
- /////////////////////////////////////////////////////////////////////////////
- //
- // Generated from the TEXTINCLUDE 2 resource.
- //
- #include "afxres.h"
-
- /////////////////////////////////////////////////////////////////////////////
- #undef APSTUDIO_READONLY_SYMBOLS
-
-
- #ifdef APSTUDIO_INVOKED
- /////////////////////////////////////////////////////////////////////////////
- //
- // TEXTINCLUDE
- //
-
- 1 TEXTINCLUDE DISCARDABLE
- BEGIN
- "resource.h\0"
- END
-
- 2 TEXTINCLUDE DISCARDABLE
- BEGIN
- "#include ""afxres.h""\r\n"
- "\0"
- END
-
- 3 TEXTINCLUDE DISCARDABLE
- BEGIN
- "#include ""res\\SR.rc2"" // non-Microsoft Visual C++ edited resources\r\n"
- "\r\n"
- "#define _AFX_NO_SPLITTER_RESOURCES\r\n"
- "#define _AFX_NO_OLE_RESOURCES\r\n"
- "#define _AFX_NO_TRACKER_RESOURCES\r\n"
- "#define _AFX_NO_PROPERTY_RESOURCES\r\n"
- "#include ""afxres.rc"" // Standard components\r\n"
- "\0"
- END
-
- /////////////////////////////////////////////////////////////////////////////
- #endif // APSTUDIO_INVOKED
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Icon
- //
-
- IDR_MAINFRAME ICON DISCARDABLE "res\\SR.ico"
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Dialog
- //
-
- IDD_ABOUTBOX DIALOG DISCARDABLE 34, 22, 217, 55
- STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
- CAPTION "About SR"
- FONT 8, "MS Sans Serif"
- BEGIN
- ICON IDR_MAINFRAME,IDC_STATIC,11,9,18,20
- LTEXT "SR Version 1.0",IDC_STATIC,40,10,119,8
- LTEXT "Copyright \251 1996",IDC_STATIC,40,25,119,8
- DEFPUSHBUTTON "OK",IDOK,176,6,32,14,WS_GROUP
- END
-
- IDD_SR_DIALOG DIALOG DISCARDABLE 0, 0, 185, 92
- STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
- CAPTION "SR"
- FONT 8, "MS Sans Serif"
- BEGIN
- DEFPUSHBUTTON "OK",IDOK,129,6,50,14
- PUSHBUTTON "Cancel",IDCANCEL,129,23,50,14
- CONTROL "CLASS",IDC_CLASS,"Button",BS_OWNERDRAW | WS_TABSTOP,9,6,
- 49,14
- END
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Version
- //
-
- VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,0,1
- PRODUCTVERSION 1,0,0,1
- FILEFLAGSMASK 0x3fL
- #ifdef _DEBUG
- FILEFLAGS 0x1L
- #else
- FILEFLAGS 0x0L
- #endif
- FILEOS 0x4L
- FILETYPE 0x1L
- FILESUBTYPE 0x0L
- BEGIN
- BLOCK "StringFileInfo"
- BEGIN
- BLOCK "040904B0"
- BEGIN
- VALUE "CompanyName", "\0"
- VALUE "FileDescription", "SR MFC Application\0"
- VALUE "FileVersion", "1, 0, 0, 1\0"
- VALUE "InternalName", "SR\0"
- VALUE "LegalCopyright", "Copyright \251 1996\0"
- VALUE "LegalTrademarks", "\0"
- VALUE "OriginalFilename", "SR.EXE\0"
- VALUE "ProductName", "SR Application\0"
- VALUE "ProductVersion", "1, 0, 0, 1\0"
- END
- END
- BLOCK "VarFileInfo"
- BEGIN
- VALUE "Translation", 0x409, 1200
- END
- END
-
-
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // Bitmap
- //
-
- CLASSD BITMAP DISCARDABLE "res\\classd.bmp"
- CLASSF BITMAP DISCARDABLE "res\\classf.bmp"
- CLASSU BITMAP DISCARDABLE "res\\classu.bmp"
- CLASSX BITMAP DISCARDABLE "res\\classx.bmp"
-
- /////////////////////////////////////////////////////////////////////////////
- //
- // String Table
- //
-
- STRINGTABLE DISCARDABLE
- BEGIN
- ID_INDICATOR_EXT "EXT"
- ID_INDICATOR_CAPS "CAP"
- ID_INDICATOR_NUM "NUM"
- ID_INDICATOR_SCRL "SCRL"
- ID_INDICATOR_OVR "OVR"
- ID_INDICATOR_REC "REC"
- END
-
- STRINGTABLE DISCARDABLE
- BEGIN
- IDS_ABOUTBOX "&About SR..."
- END
-
-
- #ifndef APSTUDIO_INVOKED
- /////////////////////////////////////////////////////////////////////////////
- //
- // Generated from the TEXTINCLUDE 3 resource.
- //
- #include "res\SR.rc2" // non-Microsoft Visual C++ edited resources
-
- #define _AFX_NO_SPLITTER_RESOURCES
- #define _AFX_NO_OLE_RESOURCES
- #define _AFX_NO_TRACKER_RESOURCES
- #define _AFX_NO_PROPERTY_RESOURCES
- #include "afxres.rc" // Standard components
-
- /////////////////////////////////////////////////////////////////////////////
- #endif // not APSTUDIO_INVOKED
-
- >========== SRdlg.h (definition of the dialog window) ================<
-
- // SRdlg.h : header file
- //
-
- /////////////////////////////////////////////////////////////////////////////
- // CSRDlg dialog
-
- class CSRDlg : public CDialog
- {
- // Construction
- public:
- CSRDlg(CWnd* pParent = NULL); // standard constructor
-
- // Dialog Data
- //{{AFX_DATA(CSRDlg)
- enum { IDD = IDD_SR_DIALOG };
- // NOTE: the ClassWizard will add data members here
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CSRDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Attributes
- protected:
- CBitmapButton m_class;
-
- // Implementation
- protected:
- HICON m_hIcon;
-
- // Generated message map functions
- //{{AFX_MSG(CSRDlg)
- virtual BOOL OnInitDialog();
- afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
- afx_msg void OnPaint();
- afx_msg HCURSOR OnQueryDragIcon();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
-
- >============ SRdlg.CPP (the implementation of the dialog) ========<
-
- // SRdlg.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "SR.h"
- #include "SRdlg.h"
-
- #ifdef _DEBUG
- #undef THIS_FILE
- static char BASED_CODE THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // Implementation
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //{{AFX_MSG(CAboutDlg)
- virtual BOOL OnInitDialog();
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg message handlers
-
- BOOL CAboutDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CenterWindow();
-
- // TODO: Add extra about dlg initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CSRDlg dialog
-
- NULL*/)
- : CDialog(CSRDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSRDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- void CSRDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSRDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CSRDlg, CDialog)
- //{{AFX_MSG_MAP(CSRDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CSRDlg message handlers
-
- BOOL CSRDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- CenterWindow();
-
- // Add "About..." menu item to system menu.
-
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
-
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
-
- // TODO: Add extra initialization here
- VERIFY(m_class.AutoLoad(IDC_CLASS, this));
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CSRDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CSRDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CSRDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
-